package com.zm.spring.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.*;

import java.util.ArrayList;

@Configuration
//@ComponentScan("com.zm.spring.demo")
@ComponentScan({"com.zm.spring.demo.mapper",
        "com.zm.spring.demo.biz",
        "com.zm.spring.demo.web"})
public class AnnoConfig {
    @Bean("person") //<bean id="person">
    @Lazy
    @DependsOn("aaaa")
    public Person person(){
        return new Person();
    }
    @Bean("aaaa") //<bean id="aaaa">
    @Primary
    public Person aaaa(){
        return new Person("李四",18);
    }

    @Bean //<bean id="person1">
    @Lazy
    public Person person1(){
        return Person.staticCreate();
    }

    @Bean(initMethod = "init",destroyMethod = "destroy") //<bean id="person2"> 接口注入
    public Person person2(@Autowired @Qualifier("person1") Person person1){
        return person1.create();
    }

    @Bean //<bean id="person3"> 接口注入
    @Lazy
    @Scope("prototype")
    public Person person3(@Autowired @Qualifier("person1") Person person1){
        Person person = new Person();
        person.setName("武松");
        person.setAge(35);
        person.likes = new ArrayList<>();
        person.likes.add("五枪弄棒");
        person.likes.add("弄棒");
        person.mather = new Person();
        person.mather.setName("武松他妈");
        person.father = person1;
        return person;
    }
}
